<%--
  User: 居泽平
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>


<c:if test="${isPage == 1}">
<html>
<head>
    <title>SystemUser列表</title>
    <jsp:include page="/include/common.jsp" />
    <script type="text/javascript" src="<c:url value="/resources/lib/jquery/plugin/jquery.form.min.js" />"></script>
    <script type="text/javascript" src="<c:url value="/resources/js/verify.js" />"></script>
</head>
<body>
</c:if>
<script>
    jQuery.fn.extend({
        uploadPreview: function (opts) {
            var _self = this,
                    _this = $(this);
            opts = jQuery.extend({
                Img: "ImgPr",
                Width: 100,
                Height: 100,
                ImgType: ["gif", "jpeg", "jpg", "bmp", "png"],
                Callback: function () {}
            }, opts || {});
            _self.getObjectURL = function (file) {
                var url = null;
                if (window.createObjectURL != undefined) {
                    url = window.createObjectURL(file)
                } else if (window.URL != undefined) {
                    url = window.URL.createObjectURL(file)
                } else if (window.webkitURL != undefined) {
                    url = window.webkitURL.createObjectURL(file)
                }
                return url
            };
            _this.change(function () {
                if (this.value) {
                    if (!RegExp("\.(" + opts.ImgType.join("|") + ")$", "i").test(this.value.toLowerCase())) {
                        alert("选择文件错误,图片类型必须是" + opts.ImgType.join("，") + "中的一种");
                        this.value = "";
                        return false
                    }
                    if ( $.support) {
                        try {
                            $("#" + opts.Img).attr('src', _self.getObjectURL(this.files[0]))
                        } catch (e) {
                            var src = "";
                            var obj = $("#" + opts.Img);
                            var div = obj.parent("div")[0];
                            _self.select();
                            if (top != self) {
                                window.parent.document.body.focus()
                            } else {
                                _self.blur()
                            }
                            src = document.selection.createRange().text;
                            document.selection.empty();
                            obj.hide();
                            obj.parent("div").css({
                                'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)',
                                'width': opts.Width + 'px',
                                'height': opts.Height + 'px'
                            });
                            div.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = src
                        }
                    } else {
                        $("#" + opts.Img).attr('src', _self.getObjectURL(this.files[0]))
                    }
                    opts.Callback()
                }
            })
        }
    });
    $(function () {
        $("#nikeFile").change(function(){
            $("#ImgPr").show();
        });
        $("#nikeFile").uploadPreview({ Img: "ImgPr", Width: 120, Height: 120 });
    });
</script>

<form id="myFormSystemUser" name="" method="post" enctype="multipart/form-data">
    <table class="table-container">
        <tr>
            <td class="item-name">&nbsp;</td>
            <td class="item-value">
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitEdit()">提交</a>
                <c:if test="${isPage != 1}">
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="closeWindow('#wSystemUser')">取消</a>
                </c:if>
            </td>
        </tr>
        <c:if test="${systemUser != null}">
        <tr>
            <td class="item-name">编号：</td>
            <td class="item-value">
                <p>${systemUser.id}</p>
                <input type="hidden" name="id" value="${systemUser.id}" />
            </td>
        </tr>
        </c:if>
        <tr>
            <td></td>
            <td>
                <div><img id="ImgPr" width="120" height="120" src="<c:url value='${systemUser.resource.resPath}'/>"<c:if test="${systemUser.resource == null}">style="display: none;" </c:if> /></div></td>
        </tr>
        <tr>
            <td class="item-name">头像：</td>
            <td class="item-value">
                <input type="file" name="nikeFile" id="nikeFile" />
            </td>
        </tr>
        <tr>
            <td class="item-name">登陆帐户：</td>
            <td class="item-value">
                <input type="text" name="userAccount" value="${systemUser.userAccount}" />
            </td>
        </tr>



        <tr>
            <td class="item-name">登陆密码：</td>
            <td class="item-value">
                <input type="text" name="userPassword" value="${systemUser.userPassword}" />
            </td>
        </tr>
        <tr <c:if test="${isPage == 1}">style="display:none;"</c:if>>
            <td class="item-name">用户姓名：</td>
            <td class="item-value">
                <input type="text" name="userName" value="${systemUser.userName}" />
            </td>
        </tr>
        <tr >
            <td class="item-name">用户手机：</td>
            <td class="item-value">
                <input type="text" name="mobile" value="${systemUser.mobile}" />
            </td>
        </tr>
        <tr>
            <td class="item-name">用户邮箱：</td>
            <td class="item-value">
                <input type="text" name="email" value="${systemUser.email}" />
            </td>
        </tr>
        <tr>
            <td class="item-name">用户职务：</td>
            <td class="item-value">
                <input type="text" name="postion" value="${systemUser.postion}" />
            </td>
        </tr>
        <tr>
            <td class="item-name">用户部门：</td>
            <td class="item-value">
                <input name="department" class="department1" value="1" type="checkbox" <c:if test="${systemUser.departmentMark == 1 || systemUser.departmentMark == 3}">checked</c:if>/>&nbsp;发改委&nbsp;&nbsp;
                <input name="department" class="department2" value="2" type="checkbox" <c:if test="${systemUser.departmentMark == 2 || systemUser.departmentMark == 3}">checked</c:if>/>&nbsp;统计局
            </td>
        </tr>
        <tr>
            <td class="item-name"  valign="top">用户角色：</td>
            <td class="item-value">
                <ul style="list-style-type:none">
                        <c:forEach items="${roleList}" var="role">
                            <li>
                            <input type="checkbox" name="systemRoleid" value="${role.id}"
                            <c:forEach items="${systemUser.systemRoleSet}" var="urole">
                                   <c:if test="${role.id==urole.id}">checked="checked"</c:if>
                            </c:forEach>
                                <%--<c:if test="${role.roleId==systemUser.systemRole.roleId}">selected="selected"</c:if>--%>>
                            ${role.roleName}
                            </li>
                        </c:forEach>

                </ul>

            </td>
        </tr>
      <c:if test="${systemUser != null}">
        <tr>
            <td class="item-name">当前管理地区：</td>
            <td class="item-value">
                <div id="addressArea">${addressName}</div>
            </td>
        </tr>
       </c:if>
        <input type="hidden" id="address_id" name="address_id" value="${systemUser.address.id}" />
        <tr>
            <td class="item-name">编辑管理地区：</td>
            <td class="item-value">
               <select id="city" name="city">
                   <option value="">-请选择市-</option>
                   <c:forEach items="${citys}" var="city">
                       <option value="${city.id}">${city.addrName}</option>
                   </c:forEach>
               </select>
                <select id="area" name="area">
                    <option value="">-请选择区-</option>
                </select>
                <select id="street" name="street">
                    <option value="">-请选择街道-</option>
                </select>
            </td>
        </tr>
         <c:if test="${systemUser.departmentMark==1 || systemUser.departmentMark == 3}">
             <tr id="userInfo">
                 <td class="item-name"  valign="top">行业：</td>
                 <td class="item-value">
                     <div ><input type="checkbox"  onclick="chooiseAll(this);">全部</div>
                     <div >
                         <c:forEach items="${industryList}" var="indus">
                             <input type="checkbox" name="industr" class="industr" value="${indus.id}"
                             <c:if test="${systemUser != null}">
                             <c:forEach items="${systemUser.industrySet}" var="ingetID">
                             <c:if test="${ingetID.id == indus.id}">
                                    checked="checked"
                             </c:if>
                             </c:forEach>
                             </c:if>
                             >${indus.industryName}
                         </c:forEach>
                     </div>
                 </td>
             </tr>
         </c:if>
        <c:if test="${systemUser.departmentMark==2 || systemUser.departmentMark == 3}">
            <tr id="Info">
                <td class="item-name"  valign="top">亿元行业：</td>
                <td class="item-value">
                    <div ><input type="checkbox"  onclick="chooiseAll1(this);">全部</div>
                    <div >
                        <c:forEach items="${industryLists}" var="indus">
                            <input type="checkbox" name="industr" class="industr1" value="${indus.id}"
                            <c:if test="${systemUser != null}">
                            <c:forEach items="${systemUser.industrySet}" var="ingetID">
                            <c:if test="${ingetID.id == indus.id}">
                                   checked="checked"
                            </c:if>
                            </c:forEach>
                            </c:if>
                            >${indus.industryName}
                        </c:forEach>
                            <%--<input type="checkbox" name="industr" class="industr1" value="${otherIndustry}"><label>其他</label>--%>
                    </div>
                </td>
            </tr>
        </c:if>
<c:if test="${systemUser.departmentMark == null}">
        <tr style="visibility:hidden" id="userInfo">
            <td class="item-name"  valign="top">行业：</td>
            <td class="item-value">
                <div ><input type="checkbox"  onclick="chooiseAll(this);">全部</div>
                <div >
                    <c:forEach items="${industryList}" var="indus">
                    <input type="checkbox" name="industr" class="industr" value="${indus.id}"
                        <c:if test="${systemUser != null}">
                            <c:forEach items="${systemUser.industrySet}" var="ingetID">
                        <c:if test="${ingetID.id == indus.id}">
                            checked="checked"
                    </c:if>
                    </c:forEach>
                            </c:if>
                            >${indus.industryName}
                    </c:forEach>
                </div>
            </td>
        </tr>

        <tr style="visibility:hidden" id="Info">
            <td class="item-name"  valign="top">亿元行业：</td>
            <td class="item-value">
                <div ><input type="checkbox"  onclick="chooiseAll1(this);">全部</div>
                <div >
                    <c:forEach items="${industryLists}" var="indus">
                        <input type="checkbox" name="industr" class="industr1" value="${indus.id}"
                        <c:if test="${systemUser != null}">
                        <c:forEach items="${systemUser.industrySet}" var="ingetID">
                        <c:if test="${ingetID.id == indus.id}">
                               checked="checked"
                        </c:if>
                        </c:forEach>
                        </c:if>
                        >${indus.industryName}
                    </c:forEach>
                    <%--<input type="checkbox" name="industr" class="industr1" value="${otherIndustry}"><label>其他</label>--%>
                </div>
            </td>
        </tr>
    </c:if>
    </table>
</form>

<script type="text/javascript">
    function chooiseAll(obj){
        if(obj.checked){
            $("[class='industr']:checkbox").prop('checked',true);
        }else{
            $("[class='industr']:checkbox").removeAttr("checked");
        }
    }
    function chooiseAll1(obj){
        if(obj.checked){
            $("[class='industr1']:checkbox").prop('checked',true);
        }else{
            $("[class='industr1']:checkbox").removeAttr("checked");
        }
    }

    $("#city").change(function(){
        $.ajax({url:'<c:url value="/admin/address/findByParentID.action" />',data:{id:$("#city").val()},dataType:'json',success:function(data){
            $("#area").empty();
            $("#area").append('<option value="">-请选择区-</option>');
            $("#street").empty();
            $("#street").append('<option value="">-请选择街道-</option>');
            $(data.result).each(function(index,ele){

               $("#area").append('<option value="'+ele.id+'">'+ele.name+'</option>');
            });
        }});
    });
    $("#area").change(function(){
        $.ajax({url:'<c:url value="/admin/address/findByParentID.action" />',data:{id:$("#area").val()},dataType:'json',success:function(data){
            $("#street").empty();
            $("#street").append('<option value="">-请选择街道-</option>');
            $(data.result).each(function(index,ele){
                $("#street").append('<option value="'+ele.id+'">'+ele.name+'</option>');
            });
        }});
    });

  function submitEdit(){
      if($.trim($("#city").val())!=""||$.trim($("#addressArea").html())!=""){
          if($.trim($("#street").val())!=""){
              $("#address_id").val($("#street").val());
          }else if($.trim($("#area").val())!=""){
              $("#address_id").val($("#area").val());
          }else if($.trim($("#city").val())!=""){
              $("#address_id").val($("#city").val());
          }
      }else{
          alert("请选择管理地区");
          return false;
      }

        $("#myFormSystemUser").form('submit', {
            url: '<c:url value="/web/admin/systemUser/executeSystemUserEdit.action" />',
            onSubmit: function(){
                if(!$(this).form('validate')){
                    return false;
                }
                $.messager.progress({
                    title:'操作中',
                    msg:'正在操作。。。'
                });
                return true;
            },
            success: function(data){
                $.messager.progress('close');
                if(data == 1){
                    <c:if test="${isPage != 1}">
                    $("#wSystemUser").window('close');
                    $('#dgSystemUser').datagrid('reload');
                    </c:if>
                    <c:if test="${isPage == 1}">
                    $.messager.alert("提示", "修改成功", 'info');
                    </c:if>
                } else {
                    $.messager.alert("出错了", data, 'error');
                }
            }
        });
    }

    $(function () {
        $(".department1").click(function () {
            if ($(".department1").is(":checked")) {
                $("#userInfo").css("visibility", "block");
            }
            else {
                $("#userInfo").css("visibility", "hidden");
            }
        });
    });

    $(function () {
        $(".department2").click(function () {
            if ($(".department2").is(":checked")) {
                $("#Info").css("visibility", "block");
            }
            else {
                $("#Info").css("visibility", "hidden");
            }
        });
    });
</script>


<c:if test="${isPage == 1}">
</body>
</html>
</c:if>